package main

import "fmt"

type A struct {
	Name string
	age  int
}

type C struct {
	Name string
	age  int
}

func (a *A) SayOk() {
	fmt.Println("A SayOk", a.Name)
}

func (a *A) hello() {
	fmt.Println("A hello", a.Name)
}

type B struct {
	A
	C
	Name string
}

func (b *B) SayOk() {
	fmt.Println("B SayOk", b.Name)
}

type D struct {
	a A // 有名结构体
}

type E struct {
	A
}
type F struct {
	*A
}

func main() {
	// 结构体嵌入 大小写都可以使用
	b := B{}
	b.Name = "zw"
	b.A.age = 12   // 必须指定
	b.SayOk()      //B SayOk zw
	b.hello()      // A hello
	fmt.Println(b) //{{ 12} { 0} zw}

	var d D
	d.a.age = 10

	b2 := B{
		A:    A{Name: "zw", age: 12},
		C:    C{Name: "zw1", age: 14},
		Name: "zz",
	}
	fmt.Println(b2) // {{zw 12} {zw1 14} zz}

	e := E{
		A{Name: "ee", age: 12},
	}
	fmt.Println(e) // {{ee 12}}
	f := F{
		&A{Name: "ee", age: 12},
	}
	fmt.Println(*f.A) // {ee 12}
}
